package dev.alm.java11boot276.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("login interceptor");
        String token = request.getHeader("token");
        log.info("token: " + token);
        if (Strings.isEmpty(token)) {
            log.info("token is empty");
            throw new Exception("token is empty");
        }
        return true;
    }
}
